let sinon = require("sinon");
let menu = require('../lib/menu');
let addStudent = require('../lib/addStudent');
let printReport = require('../lib/printReport');

let main = require("../lib/main");

describe('menu()', () => {

    it('should display main menu once started', () => {
        sinon.spy(console, 'log');
        menu();
        expect(console.log.args.join()).toBe(`1. 添加学生
2. 生成成绩单
3. 退出
请输入你的选择（1～3）：`);
    });
});
describe('addStudent',()=>{
    // it('input info false',()=>{
    //     let studentInfo = `张三,21,33,汉,数学:78`;
    //     spyOn(console, 'log');                
    //     addStudent();
    //     expect(console.log).toHaveBeenCalledWith(`请按正确的格式输入（格式：姓名, 学号, 学科: 成绩, ...）：`);
    // });
    it('input info true',()=>{
        let studentInfo = `张三,1704,汉,11,数学:78,语文:88,英语:67,编程:90`;
        spyOn(console, 'log');        
        let student_obj = addStudent(studentInfo);
        expect(console.log).toHaveBeenCalledWith('学生张三的成绩被添加');
        expect(student_obj).toEqual({ name: '张三', id: '1704', ethnic: '汉', classs: '11', 数学: '78', 语文: '88', 英语: '67', 编程: '90' });

    });
});
describe('printReport',()=>{
    it('print report card',()=>{
        let students = [{ name: '张三', id: '1704', ethnic: '汉', classs: '11', 数学: '78', 语文: '88', 英语: '67', 编程: '90' },
        { name: '李四', id: '1614', ethnic: '汉', classs: '11', 数学: '100', 语文: '68', 英语: '97', 编程: '99' }];
        let id = '1704';
        spyOn(console, 'log');        
        printReport(students,id);
        let result = `姓名|数学|语文|英语|编程|平均分|总分
========================
张三|78|88|67|90|80.8|323
李四|100|68|97|99|91.0|364
========================
全班总分平均数：xxx
全班总分中位数：xxx`;
        expect(console.log).toHaveBeenCalledWith(result);
    
    })
})
